#ifndef __C_ARCH_INOUT_H__
#define __C_ARCH_INOUT_H__

#include "std/std.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef TEST_DBG_WIN32

#define outb(value, port)
#define outb_p(value, port)
#define inl(port)				(0)
#define outl(value, port)
#define inb(port)				(0)
#define inw(port)				(0)
#define outw(value, port)
#define insw(port, addr, count)
#define insl(port, addr, count)

#else

#define outb(value, port) \
	__asm__ ("outb %%al,%%dx"::"a" ((char)(value)),"d" (port))

#define outb_p(value, port) \
	__asm__ ("outb %%al,%%dx\njmp 1f\n1:jmp 1f\n1:"::"a" ((char)(value)),"d" (port))

#define inl(port) ({\
	unsigned long _v;	\
	__asm__ volatile ("inl %%dx,%%eax":"=a" (_v):"d" (port)); \
	_v; \
})

#define outl(value, port) \
	__asm__ ("outl %%eax,%%dx"::"a" ((long)(value)),"d" (port))

#define inb(port) ({ \
	unsigned char _v; \
	__asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \
	_v; \
})

#define inw(port) ({ \
	unsigned short _v; \
	__asm__ volatile ("inw %%dx,%%ax":"=a" (_v):"d" (port)); \
	_v; \
})

#define outw(value, port) \
	__asm__ ("outw %%ax,%%dx"::"a" ((short)(value)),"d" (port))

static inline void insw(unsigned short port, void * addr, unsigned long count)
{
	__asm__ __volatile__ ("rep ; insw"
	: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count));
}

static inline void insl(unsigned short port, void * addr, unsigned long count)
{
	__asm__ __volatile__ ("rep ; insl"
		: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count));
}

#endif

#ifdef __cplusplus
}
#endif
#endif
/* EOF */
